#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> arr(n);
    ll a, b;
    ll i = 0;
    ll min = 0;
    for (i = 0; i < n; i++)
    {
        cin >> a >> b;
        arr[i] = {a, b};
    }
    sort(arr.begin(), arr.end());
    ll mul = 0;
    ll ans = 0;
    for (auto &ele : arr)
    {
        mul += ele.second;
        // if (ele.first - mul <= 0 && ans < ele.first + m)
        // {
        //     ans = ele.first + m;
        // }
        // else
        if (ele.first - mul <= m && ans < m + mul)
        {
            ans = m + mul;
        }
    }
    if (ans < m)
        ans = m;
    cout << ans << endl;
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
